package com.itheima.polymorpic.practice01;

public class Test4Polymorpic {
    public static void main(String[] args) {
        userAnimal(new Dog01());
        userAnimal(new Cat01());

    }

    public static void userAnimal(Animal01 animal01) {
        animal01.eat();
        // 判断animal01变量记录的类型, 是否是Dog01
        if (animal01 instanceof Dog01) {
            Dog01 dog01 = (Dog01) animal01;
            dog01.watchhome();
        }

    }
}

abstract class Animal01 {
    public abstract void eat();
}

class Dog01 extends Animal01 {

    @Override
    public void eat() {
        System.out.println("狗吃肉");
    }

    public void watchhome() {
        System.out.println("狗吃肉");
    }
}

class Cat01 extends Animal01 {

    @Override
    public void eat() {
        System.out.println("猫吃鱼");

    }
}